using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using HISModels.Entities;

namespace HISModels.Mapping
{
	public class ItemMap : EntityTypeConfiguration<Item>
	{
		public ItemMap()
		{
			// Primary Key
			this.HasKey(t => t.Id);

			// Properties
			this.Property(t => t.CodeValue)
				.IsRequired()
				.HasMaxLength(10);
				
			this.Property(t => t.NameValue)
				.HasMaxLength(50);
				
			// Table & Column Mappings
			this.ToTable("Items");
			this.Property(t => t.Id).HasColumnName("Id");
			this.Property(t => t.CodeValue).HasColumnName("CodeValue");
			this.Property(t => t.NameValue).HasColumnName("NameValue");
			this.Property(t => t.ItemSubCategoryId).HasColumnName("ItemSubCategoryId");
			this.Property(t => t.ItemShapeId).HasColumnName("ItemShapeId");
			this.Property(t => t.RecordStatus).HasColumnName("RecordStatus");
			this.Property(t => t.ItemDrugTypeId).HasColumnName("ItemDrugTypeId");

			// Relationships
			this.HasOptional(t => t.RefItemSubCategory)
				.WithMany(t => t.Items)
				.HasForeignKey(d => d.ItemSubCategoryId);
				
			this.HasOptional(t => t.RefItemDrugType)
				.WithMany(t => t.Items)
				.HasForeignKey(d => d.ItemDrugTypeId);
				
			this.HasOptional(t => t.RefItemShape)
				.WithMany(t => t.Items)
				.HasForeignKey(d => d.ItemShapeId);
				
		}
	}
}

